package com.im.common.result;

import com.im.common.enums.ResultEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用返回对象
 *
 * @author yunZhouJiaDi
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult<T> {

    @ApiModelProperty("code码")
    private long code;

    @ApiModelProperty("提示信息")
    private String message;

    @ApiModelProperty("数据")
    private T data;

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<T>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static <T> JsonResult<T> failed(String message) {
        return new JsonResult<T>(ResultEnum.FAILED.getCode(), message, null);
    }

    public static JsonResult error(int code, String msg) {
        return new JsonResult(code, msg, null);
    }

}
